package com.yuezhu.constomview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yuezhu.R;
import com.yuezhu.util.StringUtil;

public class TitleView extends RelativeLayout  {
	public   static  final  int RIGHT_MID = 1;
	public  static  final  int MID = 2;
	public  static  final  int LEFT_MID = 3;
	public  static  final  int RIGHT_MID_LEFT = 4 ;
	// title lefttext,midtext ,righttext ;
	private TextView title_left, title_mid, title_right;
	private TitleListener titleListener;

	public TitleView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		initView();
	}

	public TitleView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
		initView();
	}

	public TitleView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		initView();
	}

	private void initView() {
		View view = LayoutInflater.from(getContext()).inflate(
				R.layout.title_layout, this);
		title_left = (TextView) findViewById(R.id.title_bac);
		title_mid = (TextView) findViewById(R.id.title_text);
		title_right = (TextView) findViewById(R.id.title_yes);
	}

	public TitleView initTitleContent(String left, String mid, String right,
								 TitleListener titleListener) {
		this.titleListener = titleListener;
		title_mid.setText(mid);
		title_left.setText(left);
		title_right.setText(right);
		return  this;
	}
	public  TitleView  setTitleViewListener(OnClickListener listener){
		title_left.setOnClickListener(listener);
		title_right.setOnClickListener(listener);
		return  this;
	}
public  void  setStaus(int status){
	switch (status){
		case RIGHT_MID:
			title_right.setVisibility(VISIBLE);
			title_mid.setVisibility(VISIBLE);
			title_left.setVisibility(GONE);
			break;
		case MID:
			title_right.setVisibility(GONE);
			title_mid.setVisibility(VISIBLE);
			title_left.setVisibility(GONE);
			break;
		case RIGHT_MID_LEFT:
			title_right.setVisibility(VISIBLE);
			title_mid.setVisibility(VISIBLE);
			title_left.setVisibility(VISIBLE);
			break;
		case LEFT_MID:
			title_right.setVisibility(GONE);
			title_mid.setVisibility(VISIBLE);
			title_left.setVisibility(VISIBLE);
			break;
	}
}

	public interface TitleListener {
		void leftClick();

		void rightClick();
	}
}
